Repository navigation
fix(ingester): do not retain unfiltered postings in lazy-matcher cache entries - #7992
Merged
alanprot merged 2 commits intoDec 4, 2026
Merged
Conversation
…e entries fetchWithLazyMatchers filtered in place with filtered := ids[:0], so the cached slice kept the whole expanded postings array reachable while the cache charged only len(filtered)*8 bytes. A query whose lazy matchers kept a few series out of many held far more memory than max_bytes accounted for. Copy the filtered refs into an exact-size slice when filtering removed anything. Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
yeya24
approved these changes
Dec 4, 2026
alanprot
enabled auto-merge (squash)
December 4, 2026 17:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
Fixes the expanded postings cache keeping the whole unfiltered postings list in memory for entries resolved with lazy matchers.
fetchWithLazyMatchersfilters in place withfiltered := ids[:0]. The returned slice shares the backing array of every series the selective matchers returned, but the cache charges the entry onlylen(filtered)*8bytes. A query whose lazy matchers keep a few series out of many therefore holds far more memory thanmax_bytesaccounts for.For example, with 50k series selected by
__name__="cpu"and a deferredpod=~"keep-.*"that keeps 10, each cached entry kept the full array reachable: 17.2 MB retained against 6.6 KB charged across 40 entries.The fix copies the filtered refs into an exact-size slice when filtering removed anything. Filtering still happens in place, and no copy is made when every series matched.
make+appendis used instead ofslices.Cloneso the capacity equals the length exactly.Which issue(s) this PR fixes:
None filed. The in-place filter came in with #7553.
Checklist
TestFetchWithLazyMatchers_ResultDoesNotRetainUnfilteredRefs: fails before the fix with cap 1280 for 2 kept refs, passes after)CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags (no new flags)